package model.dao.registerOrder;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import log.MyLogger;
import model.service.DeviceType;


public class DeviceTypeDAOImpl{
	
	String sql = "" ;
	db.dbconnection dbconnection ;
	Connection myConnection ;
	Statement st ;

	public DeviceType getDeviceTypeById(int deviceTypeId) {
		DeviceType deviceType = new DeviceType();
		deviceType.setDeviceType(deviceTypeId);
		try {
			myConnection = dbconnection.getConnection();
			Statement st = myConnection.createStatement();
			String sql = "SELECT * FROM device_type WHERE device_type = "+deviceTypeId;
			ResultSet resultSet = st.executeQuery(sql);
			while(resultSet.next()){
				deviceType.setLevel(resultSet.getInt("level"));
				deviceType.setTypeName(resultSet.getString("type_name"));
				deviceType.setSuperDeviceType(new DeviceType(resultSet.getInt("super_type_fk")));
			}
			this.dbconnection.close();
		} catch (Exception e) {
//			MyLogger.Log("DeviceTypeDAOImpl.getDeviceTypeById()", e.getMessage());
		}
		return deviceType;
	}

	public List<DeviceType> getAllDeviceTypes() {
		
		List<DeviceType> deviceTypes = new ArrayList<DeviceType>();
		;
		try {
			myConnection = dbconnection.getConnection();
			Statement st = myConnection.createStatement();
			String sql = "SELECT * FROM device_type";
			ResultSet resultSet = st.executeQuery(sql);
			while(resultSet.next()){
				DeviceType deviceType = new DeviceType();
				deviceType.setDeviceType(resultSet.getInt("device_type"));
				deviceType.setLevel(resultSet.getInt("level"));
				deviceType.setTypeName(resultSet.getString("type_name"));
				deviceType.setSuperDeviceType(new DeviceType(resultSet.getInt("super_type_fk")));
				deviceTypes.add(deviceType);
			}
		} catch (Exception e) {
//			MyLogger.Log("DeviceTypeDAOImpl.getAllDeviceTypes()", e.getMessage());
		}
		return deviceTypes;
	}

}
